import java.util.Arrays;

public class Test {
    public static void main(String[] args) {
       String str="BAabB";
       char[] ch=str.toCharArray();
       int size=0;
        char[] ch2=new char[ch.length];

        for (int i = 0; i < ch.length; i++) {
            for (int j = i+1; j <ch.length ; j++) {
                if(ch[i]!=ch[j]){
                    ch2[i]=ch[i];
                    size++;
                    break;

                }
            }
        }
        char[] ch3=Arrays.copyOfRange(ch2,0,size);
        str=new String(ch3);
        System.out.println(str);

    }
}
    char[] ch = str.toCharArray();
    int size = 0;
    char[] ch2 = new char[ch.length];
        for (int i = 0; i < ch.length; i++) {
        for (int j = i + 1; j < ch.length ; j++) {
        if (ch[i] != ch[j]) {
        ch2[i] = ch[i];
        size++;
        break;

        }
        }
        }
        char[] ch3=Arrays.copyOfRange(ch2,0,size);
        str = new String(ch3);
        return str;